package com.Darkra1Zzz.controller;

import com.Darkra1Zzz.entity.*;
import com.Darkra1Zzz.service.SongService;
import com.Darkra1Zzz.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * @Author DarkraiZzz
 * @Time 2021/6/30 14:33
 * @Version 1.0
 */
@Controller
public class SongController {

    @Resource
    private SongService songService;


    /**
     * 分页查询
     * pageIndex 当前页码
     * pageSize  显示条数
     */
    @RequestMapping(value = "findSongs")
    public String findSongs(String name,String singer,
                           String type, Integer pageIndex, Integer pageSize, Model model) {
        Song song=new Song();
        if (name!=null){
            song.setName(name);
        }
        if (type!=null){
            Type type1=new Type();
            type1.setType(type);
            song.setType(type1);
        }
        if (singer!=null){
            Singer singer1=new Singer();
            singer1.setName(singer);
            song.setSinger(singer1);
        }

        PageInfo<Song> pageInfo = songService.querySongsByCondition(song,pageIndex,pageSize);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("name",song.getName());
        return "songlist";
    }

}
